package socketinterface.commands;

import java.io.IOException;

import socketinterface.ConsoleLogger;
import socketinterface.Logger;
import socketinterface.requests.ClientRequest;

public class IoUpdate implements ICommandPacket {
	private ClientRequest   clientRequest;
	private Logger          logger;
	private final short     size = 14;
	private int             index;
	private int             state;
	
	public IoUpdate (ClientRequest clientRequest, int index, boolean state) {
		this.clientRequest = clientRequest;
		this.index = index;
		this.state = state ? Integer.valueOf(1) : Integer.valueOf(0);
		this.logger = new ConsoleLogger();
	}
	
	public void execute() {
		try {
			clientRequest.writeShort(size);
			clientRequest.writeShort(IoProtocol.PK_IO_UPDATE);
			clientRequest.writeInt(index);
			clientRequest.writeInt(state);
			clientRequest.writeShort(IoProtocol.PK_COMMAND_TERMINATE);
			clientRequest.writeFlush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
